package vue;

import interfaces.IPlateformePlugin;

import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.Image;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import frameListeners.OpenListOfPluginsFrameListener;
import frameListeners.OuvrirFenetre;

@SuppressWarnings("serial")
public class PlateformeFrame extends JFrame implements IPlateformePlugin{

	/**
	 * @param args
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @throws ClassNotFoundException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	
	private JPanel panel;
	private JMenuBar jm;
	
	public PlateformeFrame(){
		super();
		
		this.panel=new JPanel();
		this.jm = new JMenuBar();
		
		this.addBackgroundImage();
		
		this.setTitle("Just one plugin platform"); 
		this.setSize(451,(194+45));
		this.setLocationRelativeTo(null); 
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		this.panel.setLayout(new GridBagLayout());
		this.panel.setBackground(Color.white);
		this.setContentPane(this.panel);
		
		this.createMenu();
		this.buildContent();
		this.open();
	}
	
	private void addBackgroundImage() {
		// TODO Auto-generated method stub
		Image image = getToolkit().getImage("./images/jopp.png");
		JLabel background = new JLabel();
		Icon i = new ImageIcon(image);
		background.setIcon(i);
		this.panel.add(background);
	}

	private void createMenu() {
		// TODO Auto-generated method stub
		
		this.jm.setName("jm");
		this.setJMenuBar(this.jm);
		
		JMenu plugins = new JMenu("Plugins");
		plugins.setName("plugins");
		
		JMenuItem loadOnePlugin = new JMenuItem("Chargement de plugin(s)...");
		loadOnePlugin.addActionListener(new OpenListOfPluginsFrameListener());
		
		//JMenuItem loadAllPlugins = new JMenuItem("Charger tous les plugins");
		//loadAllPlugins.addActionListener(new LoadAllPluginsListener());
		
		plugins.add(loadOnePlugin);
		//plugins.add(loadAllPlugins);
		jm.add(plugins);
		
		JMenu options = new JMenu("Paramètres");
		options.setName("options");
		
		JMenuItem pluginsPath = new JMenuItem("Modifier le chemin source des plugins...");
		pluginsPath.addActionListener(new OuvrirFenetre("ModifyPluginPathFrame"));
		
		options.add(pluginsPath);
		jm.add(options);
		
		JMenu aide = new JMenu("Aide");
		aide.setName("aide");
		
		JMenuItem api = new JMenuItem("Fonctions de l'API");
		api.setName("api");
		
		JMenuItem pluginInfo = new JMenuItem("Informations création plugin");
		pluginInfo.setName("pluginInfo");
		
		aide.add(api);
		aide.add(pluginInfo);
		
		jm.add(aide);
	}

	private void buildContent() {
		// TODO Auto-generated method stub

	}
	
	public void open() {
		// TODO Auto-generated method stub
		this.setVisible(true);
	}

	@Override
	public String getNamePlugin() {
		// TODO Auto-generated method stub
		return "InterfaceGraphiquePlugin";
	}

	@Override
	public void load() {
		// TODO Auto-generated method stub
		this.open();
	}
}
